package com.cloud.core.graphx

import org.apache.spark.{SparkConf, SparkContext}
import org.apache.spark.graphx.GraphLoader

import java.util.Calendar

object ConnectedComponent_01 {

  def main(args: Array[String]): Unit = {
    val sparkConf = new SparkConf()
      .setMaster("local")
      .setAppName("ConnectedComponent_01")

    val sparkContext = new SparkContext(sparkConf)
    val graph = GraphLoader.edgeListFile(sparkContext,"data/com-lj.ungraph.txt")

    Calendar.getInstance().getTime
    val cc = graph.connectedComponents()
    Calendar.getInstance().getTime

    cc.vertices.collect()
    // 输出结果中前 5 个元素
    println(cc.vertices.take(5).mkString("\n"))

//    val scc = graph.stronglyConnectedComponents(10)
//    scc.vertices.collect()
  }

}
